//1346. 检查整数及其两倍数是否存在


#include <algorithm>
#include <vector>
using namespace std;

class Solution {
public:
    bool checkIfExist(vector<int>& arr) {
        int n = arr.size();
        // 1. 排序
        sort(arr.begin(), arr.end());
        // 2. 二分查找 O(N*logN)
        for(int i = 0; i < n-1; i++)
        {
            double key = arr[i] < 0 ? (double)arr[i]/2 : arr[i]*2;//强转防止精度丢失
            int left = i + 1, right = n - 1;
            while(left <= right)
            {
                int mid = left + (right-left)/2;//防止超出int最大范围
                if(arr[mid] < key) left = mid + 1;
                else if(arr[mid] > key) right = mid - 1;
                else return true;
            }
        }
        return false;
    }
};